$(function() 
	{
		afterRegister();
		showScitechInformation();
	});

//Register
	function showChsRegister()  
		{
			$.get('page/register-chooseoccupation.php',function(data)
				{
					$('#indexInformation').html(data);
				});
		}
	function showStdsRegister()  
		{
			$.get('page/register-std.php',function(data)
				{
					$('#indexInformation').html(data);
				});
		}
	function submitStudent()
		{	
			if($('#student_username').val()=='')
			{	
				alert("Please insert your username");
			}
			else if($('#student_password').val()=='')
			{
				alert("Please insert your password");
			}
			else if($('#student_repassword').val()=='')
			{
				alert("Please insert your repassword");
			}
			else if($('#student_repassword').val()!=$('#student_password').val())
			{
				alert("Your password and repassword are not match");
				$('#student_password').val('');
				$('#student_repassword').val('');
			}
			else if($('#student_firstname').val()=='')
			{
				alert("Please insert your firstname");
			}
			else if($('#student_lastname').val()=='')
			{
				alert("Please insert your lastname");
			}
			else if($('#student_ncuid').val()=='')
			{
				alert("Please insert your NCU ID");
			}
			else if($('#student_email').val()=='')
			{
				alert("Please insert your E-mail");
			}
			else if($('#student_faculty').val()=='')
			{
				alert("Please insert your faculty");
			}
			else if($('#student_year').val()=='')
			{
				alert("Please insert your year");
			}
			else{
			$.post('function/response-student.php',{
				'student_username' : $('#student_username').val(),
				'student_password' : $('#student_password').val(),
				'student_firstname' : $('#student_firstname').val(),
				'student_lastname' : $('#student_lastname').val(),
				'student_ncuid' : $('#student_ncuid').val(),
				'student_email' : $('#student_email').val(),
				'student_tel' : $('#student_tel').val(),
				'student_faculty' : $('#student_faculty').val(),
				'student_year' : $('#student_year').val()},
				function(data)//ทำการรีบข้อมูลมาจาก response.php โดยทำการรับข้อมูลตามที่ได้กำหนดไว้
			{
				alert("Register successful");});
				afterRegister();
			}
		}
	function showTchsRegister()  
		{
			$.get('page/register-tch.php',function(data)
				{
					$('#indexInformation').html(data);
				});
		}
	function submitTeacher()
		{	
			if($('#teacher_username').val()=='')
			{
				alert("Please insert your username");
			}
			else if($('#teacher_password').val()=='')
			{
				alert("Please insert your password");
			}
			else if($('#teacher_repassword').val()=='')
			{
				alert("Please insert your repassword");
			}
			else if($('#teacher_repassword').val()!=$('#teacher_password').val())
			{
				alert("Your password and repassword are not match");
				$('#teacher_password').val('');
				$('#teacher_repassword').val('');
			}
			else if($('#teacher_firstname').val()=='')
			{
				alert("Please insert your firstname");
			}
			else if($('#teacher_lastname').val()=='')
			{
				alert("Please insert your lastname");
			}
			else if($('#teacher_ncuid').val()=='')
			{
				alert("Please insert your NCU ID");
			}
			else if($('#teacher_email').val()=='')
			{	
				alert("Please insert your email");
			}
			else{
			$.post('function/response-teacher.php',{
				'teacher_username' : $('#teacher_username').val(),
				'teacher_password' : $('#teacher_password').val(),
				'teacher_firstname' : $('#teacher_firstname').val(),
				'teacher_lastname' : $('#teacher_lastname').val(),
				'teacher_ncuid' : $('#teacher_ncuid').val(),
				'teacher_email' : $('#teacher_email').val(),
				'teacher_tel' : $('#teacher_tel').val(),
				'teacher_faculty' : $('#teacher_faculty').val()},
				function(data)//ทำการรีบข้อมูลมาจาก response.php โดยทำการรับข้อมูลตามที่ได้กำหนดไว้
			{ 
				
				alert("Register successful");});
				afterRegister();
				
			}
		}
	function showRegister()  
		{
			$.get('page/register-chooseoccupation.php',function(data)
				{
					$('#showInformation').html(data);
				});
		} 
	function registerStd()  
		{
			$.get('page/register-std.php',function(data)
				{
					$('#showInformation').html(data);
				});
		}
	function registerTch() 
		{
			$.get('page/register-tch.php',function(data)
				{
					$('#showInformation').html(data);
				});
		} 

//Forgotpassword
	function showForgotPassword() 
	
		{
			$.get('page/forgot-password.php',function(data)
				{
					$('#indexInformation').html(data);
				});
		}
	function forgotPassword()
		{
		$.post('function/forgot-password.php',
			{
				'forgot_username' : $('#forgotusername').val(),
				'forgot_firstname' : $('#forgotfirstname').val(),
				'forgot_ncuid' : $('#forgotncuid').val(),
				'forgot_email' : $('#forgotemail').val()
			},function(data)
			{
				if(data=="")
					{
						alert("Don't have your data in database");
					}
				else
				{	
					alert ("Your password is : "+data);
				}
			});
		}

//Show Information user
	function showScitechInformation() 
		{
			$.get('page/show-scitech.php',function(data)
				{
					scitechInformation();
					$('#adminInformation').html(data);
					$('#teacherInformation').html(data);
					$('#indexInformation').html(data);
					$('#studentInformation').html(data);
				});
		}
		function scitechInformation() 
			{
				$('#informationMain').html('Loading...');
					$.getJSON('function/json-scitech.php',function(data)
				{
				$('#informationMain').html('');
				$.each(data,function(key,val){
				$('#informationMain').html(
				$('#informationMain').html()+
				'<div id="data'+val['id']+'">'
					+'<table><tr>'
					+'<div style="display:none>"'+val['inf_id']+'</div>'
					+'<td width=150>'
					+'<font color="white" size=3>'
					+val['inf_type']
					+'</font>'
					+'</td><td width="300">'
					+'<font color="white" size=3>'
					+val['inf_subject']
					+'</font>'
					+'</td><td width="330">'
					+'<font color="white" size=3>'
					+val['inf_title']
					+'</font></div>'
					+'</td><td width=150>'
					+'<font color="white" size=3>'
					+val['inf_date_end']
					+'</font></div>'
					+'</td><td>'
					+'<font color="white" size=3 style="cursor:pointer;" onclick="userClick();" >More...</font>'
					+'</td></tr></table>'
					+'<img src="Picture-project/PNGfile/Text-line.png" width=1000>'
					);
					});
					});
			}
	function showSeInformation()  
		{
			$.get('page/show-software.php',function(data)
				{
					softwareInformation();
					$('#adminInformation').html(data);
					$('#teacherInformation').html(data);
					$('#indexInformation').html(data);
					$('#studentInformation').html(data);
				});
		}
		function softwareInformation() 

			{
				$('#informationMain').html('Loading...');
					$.getJSON('function/json-software-subject.php',function(data)
				{
				$('#informationMain').html('');
				$.each(data,function(key,val){
				$('#informationMain').html(
				$('#informationMain').html()+
				'<div id="data'+val['id']+'">'
					+'<table><tr>'
					+'<div style="display:none>"'+val['inf_id']+'</div>'
					+'<td width=150>'
					+'<font color="white" size=3>'
					+val['inf_type']
					+'</font>'
					+'</td><td width="300">'
					+'<font color="white" size=3>'
					+val['inf_subject']
					+'</font>'
					+'</td><td width="330">'
					+'<font color="white" size=3>'
					+val['inf_title']
					+'</font></div>'
					+'</td><td width=150>'
					+'<font color="white" size=3>'
					+val['inf_date_end']
					+'</font></div>'
					+'</td><td>'
					+'<font color="white" size=3 style="cursor:pointer;" onclick="userClick();" >More...</font>'
					+'</td></tr></table>'
					+'<img src="Picture-project/PNGfile/Text-line.png" width=1000>'
					);
					});
					});
			}
	function showItInformation()  
		{
			$.get('page/show-it.php',function(data)
				{
					itInformation();
					$('#adminInformation').html(data);
					$('#teacherInformation').html(data);
					$('#indexInformation').html(data);
					$('#studentInformation').html(data);
				});
		}
		function itInformation() 
			{
				$('#informationMain').html('Loading...');
					$.getJSON('function/json-it-subject.php',function(data)
				{
				$('#informationMain').html('');
				$.each(data,function(key,val){
				$('#informationMain').html(
				$('#informationMain').html()+
				'<div id="data'+val['id']+'">'
					+'<table><tr>'
					+'<div style="display:none>"'+val['inf_id']+'</div>'
					+'<td width=150>'
					+'<font color="white" size=3>'
					+val['inf_type']
					+'</font>'
					+'</td><td width="300">'
					+'<font color="white" size=3>'
					+val['inf_subject']
					+'</font>'
					+'</td><td width="330">'
					+'<font color="white" size=3>'
					+val['inf_title']
					+'</font></div>'
					+'</td><td width=150>'
					+'<font color="white" size=3>'
					+val['inf_date_end']
					+'</font></div>'
					+'</td><td>'
					+'<font color="white" size=3 style="cursor:pointer;" onclick="userClick();" >More...</font>'
					+'</td></tr></table>'
					+'<img src="Picture-project/PNGfile/Text-line.png" width=1000>'
					);
					});
					});
			}
	function showEcomInformation()  
		{
			$.get('page/show-ecom.php',function(data)
				{
					ecomInformation();
					$('#adminInformation').html(data);
					$('#teacherInformation').html(data);
					$('#indexInformation').html(data);
					$('#studentInformation').html(data);
				});
			}
		function ecomInformation() 
		{
			$('#informationMain').html('Loading...');
					$.getJSON('function/json-ecom-subject.php',function(data)
				{
				$('#informationMain').html('');
				$.each(data,function(key,val){
				$('#informationMain').html(
				$('#informationMain').html()+
				'<div id="data'+val['id']+'">'
					+'<table><tr>'
					+'<div style="display:none>"'+val['inf_id']+'</div>'
					+'<td width=150>'
					+'<font color="white" size=3>'
					+val['inf_type']
					+'</font>'
					+'</td><td width="300">'
					+'<font color="white" size=3>'
					+val['inf_subject']
					+'</font>'
					+'</td><td width="330">'
					+'<font color="white" size=3>'
					+val['inf_title']
					+'</font></div>'
					+'</td><td width=150>'
					+'<font color="white" size=3>'
					+val['inf_date_end']
					+'</font></div>'
					+'</td><td>'
					+'<font color="white" size=3 style="cursor:pointer;" onclick="userClick();" >More...</font>'
					+'</td></tr></table>'
					+'<img src="Picture-project/PNGfile/Text-line.png" width=1000>'
					);
					});
					});
		}
	function showBcomInformation()  
		{
			$.get('page/show-bcom.php',function(data)
				{
					bcomInformation();
					$('#adminInformation').html(data);
					$('#teacherInformation').html(data);
					$('#indexInformation').html(data);
					$('#studentInformation').html(data);
				});
		}
		function bcomInformation() 
		{
			$('#informationMain').html('Loading...');
					$.getJSON('function/json-bcom-subject.php',function(data)
				{
				$('#informationMain').html('');
				$.each(data,function(key,val){
				$('#informationMain').html(
				$('#informationMain').html()+
				'<div id="data'+val['id']+'">'
					+'<table><tr>'
					+'<div style="display:none>"'+val['inf_id']+'</div>'
					+'<td width=150>'
					+'<font color="white" size=3>'
					+val['inf_type']
					+'</font>'
					+'</td><td width="300">'
					+'<font color="white" size=3>'
					+val['inf_subject']
					+'</font>'
					+'</td><td width="330">'
					+'<font color="white" size=3>'
					+val['inf_title']
					+'</font></div>'
					+'</td><td width=150>'
					+'<font color="white" size=3>'
					+val['inf_date_end']
					+'</font></div>'
					+'</td><td>'
					+'<font color="white" size=3 style="cursor:pointer;" onclick="userClick();" >More...</font>'
					+'</td></tr></table>'
					+'<img src="Picture-project/PNGfile/Text-line.png" width=1000>'
					);
					});
					});
		}

		function userClick()
		{
			alert ("Please login first!");
		}

function afterRegister()
	{
		$('#student_username').val('');
		$('#student_password').val('');
		$('#student_repassword').val('');
		$('#student_firstname').val('');
		$('#student_lastname').val('');
		$('#student_ncuid').val('');
		$('#student_year').val('');
		$('#student_email').val('');
		$('#student_tel').val('');

		$('#teacher_username').val('');
		$('#teacher_password').val('');
		$('#teacher_repassword').val('');
		$('#teacher_firstname').val('');
		$('#teacher_lastname').val('');
		$('#teacher_ncuid').val('');
		$('#teacher_email').val('');
		$('#teacher_tel').val('')

		$('#subjectid').val('');
		$('#subjectname').val('');
		$('#subjectteacher').val('');

		$('#forgotusername').val('');
		$('#forgotfirstname').val('');
		$('#forgotncuid').val('');
		$('#forgotemail').val('');

		$('#title').val('');
		$('#startDate').val('');
		$('#endDate').val('');
		$('#subject').val('');
		$('#detail').val('');
	}

		function isNumberKey(evt)
       {
          var charCode = (evt.which) ? evt.which : event.keyCode;
          if (charCode < 48 || charCode > 57)
		   {
				   event.preventDefault();
			alert ("Please insert number");
		   }
		
             return true;
       }

	    function isStringKey(evt)
       {
          var charCode = (evt.which) ? evt.which : event.keyCode;
          if (charCode < 33 || charCode > 64
			&&(charCode < 91 || charCode > 96)
			&&(charCode < 123 || charCode > 126))
		   {
				return true;	
		   }
			else
		   {
				event.preventDefault();
				alert ("Can not be number");
		   }  
       }